#devtools::install_github('satijalab/seurat-wrappers')
#BiocManager::install('pcaMethods')
#devtools::install_github("velocyto-team/velocyto.R")
library(Seurat)
library(velocyto.R)
library(SeuratWrappers)

## wget 'http://pklab.med.harvard.edu/velocyto/mouseBM/SCG71.loom'
ldat <- ReadVelocity('SCG71.loom')
bm <- as.Seurat(ldat)
bm <- SCTransform(bm, assay = "spliced")
bm <- RunPCA(bm)
bm <- FindNeighbors(bm, dims = 1:20)
bm <- FindClusters(bm)
bm <- RunUMAP(bm, dims = 1:20)
bm <- RunVelocity(bm, kCells = 25, fit.quantile = 0.02)
ident.colors <- (scales::hue_pal())(n = length(levels(bm)))
names(ident.colors) <- levels(bm)
cell.colors <- ident.colors[Idents(bm)]
names(cell.colors) <- colnames(bm)
show.velocity.on.embedding.cor(emb = Embeddings(bm, reduction = "umap"),
                               vel = Tool(bm, slot = "RunVelocity"),
                               n = 200,
                               scale = "sqrt",
                               cell.colors = ac(x = cell.colors, alpha = 0.5), 
                               cex = 0.8,
                               arrow.scale = 3,
                               show.grid.flow = TRUE,
                               min.grid.cell.mass = 0.5,
                               grid.n = 40,
                               do.par = FALSE,
                               cell.border.alpha = 0.1)